﻿using Orchard;
using Orchard.ContentManagement;
using Orchard.Localization;
using Orchard.Tokens;
using Vitus.Featured.Models;

namespace Vitus.Featured.Providers.Tokens
{
    public class FeaturedPartTokens : ITokenProvider
    {
        public FeaturedPartTokens(IContentManager contentManager, IWorkContextAccessor workContextAccessor)
        {
            T = NullLocalizer.Instance;
        }

        public Localizer T { get; set; }

        public void Describe(DescribeContext context)
        {
            context.For("Content")
                .Token("FeaturedPart", T("Featured Part"), T("Tokens of the FeaturedPart."), "FeaturedPart");

            context.For("FeaturedPart", T("Featured Part"), T("Tokens of the FeaturedPart."))
                .Token("IsFeatured", T("Is Featured"), T("Determines whether the content item is featured."), "Text")
                .Token("Title", T("Featured Title"), T("Featured title."), "Text")
                .Token("Body", T("Featured Body"), T("Featured body text."), "Text")
                .Token("IsPinned", T("Is Pinned"), T("Determines whether the featured content is pinned."), "Text")
                ;
        }

        public void Evaluate(EvaluateContext context)
        {
            context.For<IContent>("Content")
                .Chain("FeaturedPart", "FeaturedPart", content => content.As<FeaturedPart>())
                ;

            context.For<FeaturedPart>("FeaturedPart")
                .Token("IsFeatured", part => part.IsFeatured.ToString())
                    .Chain("IsFeatured", "Text", part => part.IsFeatured.ToString())
                .Token("Title", part => part.Title)
                    .Chain("Title", "Text", part => part.Title)
                .Token("Body", part => part.Body)
                    .Chain("Body", "Text", part => part.Body)
                .Token("IsPinned", part => part.IsPinned.ToString())
                    .Chain("IsPinned", "Text", part => part.IsPinned.ToString())
                ;
        }
    }
}